package com.zzf.sensitive.modules.impl;

import com.google.common.collect.Lists;
import com.zzf.sensitive.aop.SensitiveMethod;
import com.zzf.sensitive.modules.TestService;
import com.zzf.sensitive.modules.dto.JsonResult;
import com.zzf.sensitive.modules.dto.TestRequest;
import com.zzf.sensitive.modules.dto.TestResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;


/**
 * 测试服务实现类
 *
 * @author zhangzhifu
 * @date 2021/1/15
 */
@Service
public class TestServiceImpl implements TestService {
    Logger logger = LoggerFactory.getLogger(this.getClass());

    @SensitiveMethod(inDecode = false)
    @Override
    public JsonResult testEncrypt(HttpServletRequest req, TestRequest request) {
        logger.info("testEncrypt request:{}", request.toString());
        TestResponse response = new TestResponse();
        BeanUtils.copyProperties(request,response);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(JsonResult.OK);
        jsonResult.setData(response);
        return jsonResult;
    }
    @SensitiveMethod(inDecode = false)
    @Override
    public JsonResult testEncrypt2(HttpServletRequest req, TestRequest request) {
        logger.info("testEncrypt request:{}", request.toString());
        TestResponse response = new TestResponse();
        BeanUtils.copyProperties(request,response);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(JsonResult.OK);
        jsonResult.setData(Lists.newArrayList(response));
        return jsonResult;
    }

    @SensitiveMethod(inDecode = false)
    @Override
    public JsonResult testEncrypt3(HttpServletRequest req, TestRequest request) {
        logger.info("testEncrypt request:{}", request.toString());
        TestResponse response = new TestResponse();
        Object [] objects ={response};
        BeanUtils.copyProperties(request,response);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(JsonResult.OK);
        jsonResult.setData( objects);
        return jsonResult;
    }

    @Override
    @SensitiveMethod(outEncode = false)
    public JsonResult testDecrypt(HttpServletRequest req, TestRequest request) {
        logger.info("testDecrypt request:{}", request.toString());
        TestResponse response = new TestResponse();
        BeanUtils.copyProperties(request,response);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(JsonResult.OK);
        jsonResult.setData(response);
        return jsonResult;
    }

    @Override
    @SensitiveMethod(outEncode = false)
    public JsonResult testDecrypt2(HttpServletRequest req, String[] strings) {
        logger.info("testDecrypt request:{}", strings);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(JsonResult.OK);
        jsonResult.setData(strings);
        return jsonResult;
    }
}

